package com.best.weixin.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.best.core.entity.CommonResult;
import com.best.weixin.service.WeiXinService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

/**
 * @ClassName: WeiXinController
 * @Package: com.best.weixin.controller
 * @Description: 微信服务接口
 * @Datetime: 2020/6/5 17:39
 * @Author: nike
 */
@Api(tags = "微信服务接口")
@RestController
@RequestMapping("/weixin")
@Slf4j
public class WeiXinController {

    @Autowired
    private WeiXinService weiXinService;

    @Value("${bestValue}")
    private String apolloValue;

    @ApiOperation(value = "微信服务测试方法")
    @GetMapping("/test")
    public String printWeiXin() {
        return "weixin test";
    }

    @ApiOperation(value = "微信服务测试feign调用方法")
    @GetMapping("/feign")
    public String testFeign() {
        return "weixin feign test";
    }

    @ApiOperation(value = "微信服务测试apollo调用方法")
    @GetMapping("/apollo")
    public String testApollo() {
        log.info("apolloValue is {}", apolloValue);
        return "weixin apollo test";
    }

    /**
     * 根据手机号码和验证码校验token是否正确
     * 
     * @param phone
     * @param weixinCode
     * @return
     */
    @ApiOperation(value = "根据手机号码验证码验证token是否正确")
    @GetMapping("/verifyCode")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "phone", dataType = "String",
                    required = true, value = "用户手机号码"),
            @ApiImplicitParam(paramType = "query", name = "weixinCode", dataType = "String",
                    required = true, value = "微信注册码")})
    public CommonResult verifyCode(String phone, String weixinCode) {
        return weiXinService.verifyCode(phone, weixinCode);
    }

}
